function initTree() {
	alert("22")
	Public.zTree.init($("#tree"), {
		defaultClass: "innerTree",
		showRoot: true,
		rootTxt: "全部"
	}, {
		callback: {		
			beforeClick: function(a, b) {
				$("#currentCategory").data("id", b.id).html(b.name), $("#search").trigger("click")
			}
		}
	})
}
function initGrid() {
	alert("11")
	var a = Public.setGrid(ajustH, ajustW),
		b = ["id", "ch_name" ,"en_name","position", "sex", "mobilephone", "department", "project_group"],
		c = parent.SYSTEM.rights,
		d = !(parent.SYSTEM.isAdmin || c.AMOUNT_COSTAMOUNT),
		e = !(parent.SYSTEM.isAdmin || c.AMOUNT_INAMOUNT),
		f = !(parent.SYSTEM.isAdmin || c.AMOUNT_OUTAMOUNT),
		g = [{
			name: 'id',
			index: 'id',
			width: 55,
			editable: true
		}, {
			name: 'ch_name',
			index: 'ch_name',
			width: 55,
			editable: true
		}, {
			name: 'en_chname',
			index: 'en_chname',
			width: 55,
			editable: true
		}, {
			name: 'position',
			index: 'position',
			width: 55,
			editable: true
		}, {
			name: 'sex',
			index: 'sex',
			width: 55,
			editable: true
		}, {
			name: 'mobilephone',
			index: 'mobilephone',
			width: 55,
			editable: true
		}, {
			name: 'department',
			index: 'department',
			width: 55,
			editable: true
		}, {
			name: 'project_group',
			index: 'project_group',
			width: 55,
			editable: true
		}];
	
	
	$("#grid").jqGrid({
		url: "listUser",
		datatype: "json",
		width: a.w,
		height: 350,
		altRows: true,
		gridview: true,
		onselectrow: false,
		colNames: b,
		colModel: g,
		pager: "#page",
		viewrecords: true,
		multiselect: true,
		cmTemplate: {
			sortable: false
		},
		sortable:true,
		rowNum: 30,
		rowList: [30, 50,100],
		shrinkToFit: true,
		jsonReader: {
			root: "rows",
			records: "records",
			total: "total",
			repeatitems: false,
			id: "id"
		},
		loadComplete: function(a) {
			if (a && 200 == a.status) {
				var b = {};
				a = a.data;
				for (var c = 0; c < a.rows.length; c++) {
					var d = a.rows[c];
					b[d.id] = d
				}
				$("#grid").data("gridData", b)
			}
		},
		loadError: function() {
			parent.Public.tips({
				type: 1,
				content: "操作失败了哦，请检查您的网络链接！"
			})
		},
		beforeSelectRow:function(rowid, e){
	          if(e.type == 'click'){
	              i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),  
	              cm = $("#grid").jqGrid('getGridParam', 'colModel');  
	              return (cm[i].name != 'operate'); 
	          }
	          return false;
	      }
	})
}
function initEvent() {
	alert("3")
	$_matchCon = $("#matchCon"), $_matchCon.placeholder(), $("#search").on("click", function(a) {
		a.preventDefault();
		var b = "按商品编号，商品名称，规格型号等查询" === $_matchCon.val() ? "" : $.trim($_matchCon.val()),
			c = $("#currentCategory").data("id");
		$("#grid").jqGrid("setGridParam", {
			page: 1,
			postData: {
				skey: b,
				assistId: c
			}
		}).trigger("reloadGrid")
	}), $("#btn-add").on("click", function(a) {
		a.preventDefault(), Business.verifyRight("INVENTORY_ADD") && handle.operate("add")
	}), $("#btn-print").on("click", function(a) {
		a.preventDefault()
	}), $("#btn-import").on("click", function(a) {
		a.preventDefault(), Business.verifyRight("BaseData_IMPORT") && parent.$.dialog({
			width: 560,
			height: 300,
			title: "批量导入",
			content: "url:settings/import",
			lock: true
		})
	}), $("#btn-export").on("click", function() {
		if (Business.verifyRight("INVENTORY_EXPORT")) {
			var a = "按商品编号，商品名称，规格型号等查询" === $_matchCon.val() ? "" : $.trim($_matchCon.val()),
				b = $("#currentCategory").data("id") || "";
			$(this).attr("href", "basedata/inventory/exporter?action=exporter&isDelete=2&skey=" + a + "&assistId=" + b)
		}
	}), $("#grid").on("click", ".operating .ui-icon-pencil", function(a) {
		if (a.preventDefault(), Business.verifyRight("INVENTORY_UPDATE")) {
			var b = $(this).parent().data("id");
			handle.operate("edit", b)
		}
	}), $("#grid").on("click", ".operating .ui-icon-trash", function(a) {
		if (a.preventDefault(), Business.verifyRight("INVENTORY_DELETE")) {
			var b = $(this).parent().data("id");
			handle.del(b + "")
		}
	}), $("#grid").on("click", ".operating .ui-icon-pic", function(a) {
		a.preventDefault();
		var b = $(this).parent().data("id"),
			c = "商品图片";
		$.dialog({
			content: "url:settings/fileUpload",
			data: {
				title: c,
				id: b,
				callback: function() {}
			},
			title: c,
			width: 775,
			height: 470,
			max: false,
			min: false,
			cache: false,
			lock: true
		})
	}), $("#btn-batchDel").click(function(a) {
		if (a.preventDefault(), Business.verifyRight("INVENTORY_DELETE")) {
			var b = $("#grid").jqGrid("getGridParam", "selarrrow");
			b.length ? handle.del(b.join()) : parent.Public.tips({
				type: 2,
				content: "请选择需要删除的项"
			})
		}
	}), $("#btn-disable").click(function(a) {
		a.preventDefault();
		var b = $("#grid").jqGrid("getGridParam", "selarrrow").concat();
		return b && 0 != b.length ? void handle.setStatuses(b, true) : void parent.Public.tips({
			type: 1,
			content: " 请先选择要禁用的商品！"
		})
	}), $("#btn-enable").click(function(a) {
		a.preventDefault();
		var b = $("#grid").jqGrid("getGridParam", "selarrrow").concat();
		return b && 0 != b.length ? void handle.setStatuses(b, false) : void parent.Public.tips({
			type: 1,
			content: " 请先选择要启用的商品！"
		})
	}), $("#hideTree").click(function(a) {
		a.preventDefault();
		var b = $(this),
			c = b.html();
		"&gt;&gt;" === c ? (b.html("&lt;&lt;"), ajustW = 0, $("#tree").hide(), Public.resizeGrid(ajustH, ajustW)) : (b.html("&gt;&gt;"), ajustW = 270, $("#tree").show(), Public.resizeGrid(ajustH, ajustW))
	}), $("#grid").on("click", ".set-status", function(a) {
		if (a.stopPropagation(), a.preventDefault(), Business.verifyRight("INVLOCTION_UPDATE")) {
			var id = $(this).data("id");
			var	status = !$(this).data("delete");
			handle.setStatus(id, status)
		}
	}), $(window).resize(function() {
		Public.resizeGrid(ajustH, ajustW), $(".innerTree").height($("#tree").height() - 95)
	}), Public.setAutoHeight($("#tree")), $(".innerTree").height($("#tree").height() - 95);

	$("#grid").on("mouseenter", ".img", function(t) {
		var e = $(this);
		if (!e.data("initFloat")) {
			var i = $(this).closest("tr")[0].id,
				a = $("#grid").jqGrid("getRowData", i),
				r = (a.files, a.files);
			if (r && r) {
				var n = $(".imgView");
				e.powerFloat({
					eventType: "hover",
					target: function() {
						return n
					},
					offsets: {
						x: 0,
						y: 0
					},
					position: "2-1",
					showCall: function(t) {
						if (e.data("initFloat", !0), e.find("img")) {
							var i = e.find("img").attr("src").replace("_80x80", "");
							$("<img/>").attr("src", i).load(function() {
								realWidth = this.width, realHeight = this.height, realWidth >= 250 ? n.attr("src", i).css("width", "250px").css("height", "250px") : n.attr("src", i).css("width", "auto").css("height", "auto")
							})
						}
					}
				}), e.trigger("mouseenter")
			}
		}
	});

}
var SYSTEM = parent.SYSTEM,
	qtyPlaces = Number(parent.SYSTEM.qtyPlaces),
	pricePlaces = Number(parent.SYSTEM.pricePlaces),
	amountPlaces = Number(parent.SYSTEM.amountPlaces),
	searchFlag = false,
	filterClassCombo, ajustH = 95,
	ajustW = 270,
	thisTree, handle = {
		operate: function(a, b) {
			var d;
			if ("add" == a) var c = "新增商品",
				d = {
					oper: a,
					callback: this.callback
				};
			else var c = "修改商品",
				d = {
					oper: a,
					rowId: b,
					callback: this.callback
				};
			var e = parent.SYSTEM.enableStorage ? 1020 : 768;
			_h = parent.SYSTEM.enableStorage ? 480 : 370, _h = parent.SYSTEM.enableAssistingProp ? _h : _h - 100, _h = parent.SYSTEM.ISSERNUM ? _h + 40 : _h;
				
	/*		$.dialog({
				title: c,
				content: "url:goods_manage.do",
				data: d,
				width: e,
				height: 430,
				max: false,
				min: false,
				cache: false,
				lock: true
			})*/
			
			parent.tab.addTabItem({
					tabid: 'setting-goodsManage',
					text: c,
					url: 'goods_manage.do?data=' + JSON.stringify(d)
				})
			
		},
		del: function(a) {
			$.dialog.confirm("删除的商品将不能恢复，请确认是否删除？", function() {
				Public.ajaxPost("goodsDelete.do", {
					id: a
				}, function(b) {
					if (b && 200 == b.status) {
						var c = b.data.id || [];
						parent.Public.tips(a.split(",").length === c.length ? {
							content: "成功删除" + c.length + "个商品！"
						} : {
							type: 2,
							content: b.data.msg
						});
						for (var d = 0, e = c.length; e > d; d++) $("#grid").jqGrid("setSelection", c[d]), $("#grid").jqGrid("delRowData", c[d])
					} else parent.Public.tips({
						type: 1,
						content: "删除商品失败！" + b.msg
					})
				})
			})
		},
		setStatus: function(a, b) {
			a && Public.ajaxPost("goodsDisable.do", {
				invIds: a,
				disable: Number(b)
			}, function(c) {
				c && 200 == c.status ? (parent.Public.tips({
					content: "商品状态修改成功！"
				}), $("#grid").jqGrid("setCell", a, "disable", b)) : parent.Public.tips({
					type: 1,
					content: "商品状态修改失败！" + c.msg
				})
			})
		},
		setStatuses: function(a, b) {
			if (a && 0 != a.length) {
				var c = $("#grid").jqGrid("getGridParam", "selarrrow"),
					d = c.join();
				Public.ajaxPost("goodsDisable.do", {
					invIds: d,
					disable: Number(b)
				}, function(c) {
					if (c && 200 == c.status) {
						parent.Public.tips({
							content: "商品状态修改成功！"
						});
						for (var d = 0; d < a.length; d++) {
							var e = a[d];
							$("#grid").jqGrid("setCell", e, "disable", b)
						}
					} else parent.Public.tips({
						type: 1,
						content: "商品状态修改失败！" + c.msg
					})
				})
			}
		},
		callback: function(a, b, c) {
			var d = $("#grid").data("gridData");
			d || (d = {}, $("#grid").data("gridData", d)), d[a.id] = a, "edit" == b ? ($("#grid").jqGrid("setRowData", a.id, a), c && c.api.close()) : ($("#grid").jqGrid("addRowData", a.id, a, "last"), c && c.resetForm(a))
		}
	},
	format = {
		money: function(a) {
			var a = Public.numToCurrency(a);
			return a || "&#160;"
		},
		currentQty: function(a) {
			if ("none" == a) return "&#160;";
			var a = Public.numToCurrency(a);
			return a
		},
		quantity: function(a) {
			var a = Public.numToCurrency(a);
			return a || "&#160;"
		},
		statusFmatter: function(t,e,a) {
		/*	var d = a === true ? "已禁用" : "已启用",
				e = a === true ? "ui-label-default" : "ui-label-success";
			return '<span class="set-status ui-label ' + e + '" data-delete="' + a + '" data-id="' + c.id + '">' + d + "</span>"
	*/
			return '<span class="set-status ' + (true === t ? "close" : "open") + '" data-delete="' + t + '" data-id="' + a.id + '"><span class="ui-icon-circle"></span></span>'
		
	}
	};
initGrid(), initTree(), initEvent();